import cv2
import numpy as np

img = np.zeros((400, 640, 3), dtype=np.uint8) + 255
cv2.namedWindow("test")

def change(x):
    b = cv2.getTrackbarPos("B", "test")
    g = cv2.getTrackbarPos("G", "test")
    r = cv2.getTrackbarPos("R", "test")
    img[:] = [b,g,r]
7
cv2.createTrackbar("B", "test", 0, 255, change)
cv2.createTrackbar("G", "test", 0, 255, change)
cv2.createTrackbar("R", "test", 0, 255, change)
while True:
    cv2.imshow("test", img)
    key = cv2.waitKey(5000)
    if key == 27:
        break
cv2.destroyAllWindows()